package cc.verywell.pureblock.func.node;

import java.lang.ref.WeakReference;
import java.net.InetSocketAddress;
import java.net.SocketAddress;

import cc.verywell.pureblock.net.NormalSession;
import cc.verywell.pureblock.util.StringUtil;

/**
* 
* 报文
* Node 报文;
* 最后连接时间[8_bit]
* 连接地址长度[2_bits] 连接地址[?_bits] 
* 
* 
* Copyright © 2019 TanYaqiu. All rights reserved.
* @author TanYaqiu 
* @address flat 601
* @date 2019年3月23日 下午7:31:44
*/
public class NodeStock {

	public Node node;
	public long lastConnect;
	public String lastRemote;
	public transient WeakReference<NormalSession> weakSession;
	
	public NodeStock(Node msg ,NormalSession ns, long time) {
		this(msg);
		if(ns!=null) {
			this.lastConnect = time;
			SocketAddress sa = /*ns==null?null:*/ns.getRemote();
			if(sa instanceof InetSocketAddress) {
				this.lastRemote = StringUtil.portToString((InetSocketAddress)sa);
			}
			weakSession = new WeakReference<>(ns);
		}
	}
	public NodeStock(Node msg) {
		this.node = msg;
	}
	public NormalSession getSession() {
		WeakReference<NormalSession> w = weakSession;
		if(w!=null)return w.get();
		return null;
	}

	
	
	

}
